<template>
  <!-- 计数规则 -->
  <div>
    <el-select
      :disabled="readonly"
      @change="changeData"
      v-model="checkedData"
      :placeholder="$t('请选择计数规则')"
      clearable
    >
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      >
      </el-option>
    </el-select>
  </div>
</template>
<script>
import nonStandardService from '@/services/nonStandardService'
export default {
  name: 'countingRules',
  props: {
    detail: {
      type: Object,
      default: () => {
        return {}
      },
    },
    value: {},
    disabled: Boolean,
    parameter: {
      type: Object,
      default: () => {
        return {}
      },
    },
  },
  data() {
    return {
      options: [
        { label: this.$t('货物数量（基础单位）'), value: '01' },
        { label: this.$t('货物净重（吨）'), value: '02' },
        { label: this.$t('货物毛重（吨）'), value: '03' },
      ],

      checkedData: null,
      selectData: null,
      readonly: false,
    }
  },
  created() {
    this.readonly = Boolean(this.$route.query.readonly)
    if (this.value) {
      this.setData()
    }
  },
  methods: {
    changeData(val) {
      let info = this.options.find((it) => it.value == val) || {}
      this.selectData = info.label
      this.$emit('input', String(this.checkedData))
    },
    setData() {
      this.selectData = JSON.parse(this.value).value
      this.checkedData = JSON.parse(this.value).checkedData
    },
    getData() {
      return {
        value: this.selectData,
        checkedData: this.checkedData,
      }
    },
  },
}
</script>
